﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using log4net;
using UniryDemo2WEB.Attribute;
using WebGrease.Activities;

namespace UniryDemo2WEB
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            log4net.Config.XmlConfigurator.Configure();

            //异常队列,,程序异常记录日志
            ThreadPool.QueueUserWorkItem(o =>
            {
                while (true)
                {
                    if (MyErrorAttribure.ExceptionsQueue.Count > 0)
                    {
                        var ex = MyErrorAttribure.ExceptionsQueue.Dequeue();
                        if (ex != null)
                        {
                            var logger = LogManager.GetLogger("testError");
                            logger.Error(ex.ToString()); //将异常信息写入Log4Net中  
                        }
                        else
                        {
                            Thread.Sleep(50);
                        }
                    }
                    else
                    {
                        Thread.Sleep(50);
                    }
                }
            });


        }
    }
}
